<template>
  <!--查看课程-->
    <el-card title="查看教学计划" width="90%">
        <el-button type="primary" size="small" @click="refreshCourses">刷新</el-button>
        <el-table :data="courses" :loading="loading" :default-sort="{prop: 'academicYear', order: 'ascending'}"
                  height="400">
            <el-table-column type="index" label="序号" width="55"/>
            <el-table-column prop="courseName" label="课程名称" width="240px"/>
            <el-table-column prop="courseCode" label="课程代码"/>
            <el-table-column prop="courseCredits" label="课程学分"/>
            <el-table-column prop="academicYear" #default="scope" label="学年" sortable min-width="100px">
                {{ yearOptions[scope.row.academicYear] }}
            </el-table-column>
            <el-table-column prop="semester" #default="scope" label="学期">
                <el-tag :type="scope.row.semester == 1?'danger':'success'">{{
                    semesterOptions[scope.row.semester]
                    }}
                </el-tag>
            </el-table-column>
            <el-table-column prop="courseOwnershipName" min-width="100px" label="课程归属"/>
            <el-table-column prop="courseCategoryName" min-width="100px" label="课程类别"/>
            <el-table-column prop="courseNatureName" min-width="100px" label="课程性质"/>
        </el-table>
    </el-card>
</template>
<script setup>

import {GetLessonPlanByStudentNumber, GetScheduleListByMajorIdAndClassesId} from "@/api/course";
import {onMounted, ref} from "vue";
import {useUserinfo} from "@/components/Avatar/hooks/useUserinfo";

const {userinfo} = useUserinfo()  // 调用导入的js文件中的useUserinfo方法，从Pinia中获取用户数据
const userInfo = userinfo
const courses = ref([])
const loading = ref(false)
const yearOptions = {
    1: '第一学年',
    2: '第二学年',
    3: '第三学年',
    4: '第四学年'
};
const semesterOptions = {
    1: '秋季学期',
    2: '春季学期'
};
// 刷新课程列表
const refreshCourses = async () => {
    courses.value = []
    loading.value = true
    setTimeout(findCourses, 500); // 500毫秒后调用findCourses函数
}
onMounted(async () => {
    await findCourses()
})
const findCourses = async () => {
    const {data} = await GetLessonPlanByStudentNumber(userInfo.value.username)
    courses.value = data
    loading.value = false; // 加载完成后，设置加载状态为false
}
</script>